define(["jqform","layuiall","jq_request","zTree","baidueditor","helper"], function (jqform,layui,jq_request,zTree,UE,helper) {
    var form  = layui.form;
    var Controller = {
        index:function () {
            jqform.delete();
            form.on('checkbox(select-all)', function(data){

                if(data.elem.checked==true){
                    $("input[name='idList[]']").prop('checked',true)
                }else {
                    $("input[name='idList[]']").prop('checked',false)
                }
                form.render('checkbox');
            });
        },
        addpost: function () {
            logic();
            jqform.init()
        },
        editpost:function () {
            logic();
            jqform.init()
        }
    }
    function logic() {
        UE.getEditor('container',{initialFrameWidth: "100%" });
        var laydate = layui.laydate;
        laydate.render({
            elem: '#publishedTime',
            type: 'datetime'
        });
        //相册上传
       /* uploadFile({
            elm:'#test1',
            url:"/admin/webupload/postupload",
            table:'.app-photos',
            multiple:true,
            exts:'jpg|png|bmp|jpeg|avg',
            inputName:'more[photos][]'
        });*/
        $("#test1").click(function () {
            uploadFiles({
                url: '/admin/webupload/webuploader/multi/1/filetype/image/app/admin/tab/local',
                file:function (res) {
                    var file = JSON.parse(res);
                    var str = '<tr>'+
                        '<td>'+
                        '<input type="text" class="layui-input" name="more[photos][]" value="'+file[0].filepath+'">'+
                        '</td>'+
                        '<td>'+
                        '<img width="80"  src="'+file[0].preview_url+'">'+
                        '</td>'+
                        '<td>'+
                        '<a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs del-photos-btn">删除</a>'+
                        '</td>'+
                        '</tr>';
                    $('.app-photos').append(str);
                    $(".del-photos-btn").click(function () {
                        $(this).parents("tr").eq($(this).index()).remove()
                    });
                    localStorage.removeItem("upload");
                }
            });
        });
        //附件件上传
        /*uploadFile({
            elm:'#test2',
            url:"/admin/webupload/postupload",
            table:'.attachment',
            multiple:true,
            exts:'jpg|png|bmp|jpeg|avg|txt|doc|docx|ico|zip|gzp',
            inputName:'more[attachments][]'
        });*/
        $("#test2").click(function () {
            uploadFiles({
                url: '/admin/webupload/webuploader/multi/1/filetype/file/app/admin/tab/local',
                file:function (res) {
                    var file = JSON.parse(res);
                    var str = '<tr>'+
                        '<td>'+
                        '<input type="text" class="layui-input" name="more[attachments][]" value="'+file[0].filepath+'">'+
                        '</td>'+
                        '<td>'+
                        '<img width="80"  src="'+file[0].preview_url+'">'+
                        '</td>'+
                        '<td>'+
                        '<a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs del-photos-btn">删除</a>'+
                        '</td>'+
                        '</tr>';
                    $('.attachment').append(str);
                    $(".del-photos-btn").click(function () {
                        $(this).parents("tr").eq($(this).index()).remove()
                    });
                    localStorage.removeItem("upload");
                }
            });
        });
        //音频上传
        /*uploadFile({
            elm:'#test3',
            url:"/admin/webupload/postupload",
            table:'.audios',
            multiple:true,
            exts:'mp3|mp4',
            inputName:'more[audios][]'
        });*/
        $("#test3").click(function () {
            uploadFiles({
                url: '/admin/webupload/webuploader/multi/1/filetype/audio/app/admin/tab/local',
                file:function (res) {
                    var file = JSON.parse(res);
                    var str = '<tr>'+
                        '<td>'+
                        '<input type="text" class="layui-input" name="more[audios][]" value="'+file[0].filepath+'">'+
                        '</td>'+
                        '<td>'+
                        '<img width="80"  src="'+file[0].preview_url+'">'+
                        '</td>'+
                        '<td>'+
                        '<a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs del-photos-btn">删除</a>'+
                        '</td>'+
                        '</tr>';
                    $('.audios').append(str);
                    $(".del-photos-btn").click(function () {
                        $(this).parents("tr").eq($(this).index()).remove()
                    });
                    localStorage.removeItem("upload");
                }
            });
        });
        //视频件上传
        /*uploadFile({
            elm:'#test4',
            url:"/admin/webupload/postupload",
            table:'.videos',
            multiple:true,
            exts:'mp3|mp4',
            inputName:'more[videos][]'
        });*/
        $("#test4").click(function () {
            uploadFiles({
                url: '/admin/webupload/webuploader/multi/1/filetype/video/app/admin/tab/local',
                file:function (res) {
                    var file = JSON.parse(res);
                    var str = '<tr>'+
                        '<td>'+
                        '<input type="text" class="layui-input" name="more[videos][]" value="'+file[0].filepath+'">'+
                        '</td>'+
                        '<td>'+
                        '<img width="80"  src="'+file[0].preview_url+'">'+
                        '</td>'+
                        '<td>'+
                        '<a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs del-photos-btn">删除</a>'+
                        '</td>'+
                        '</tr>';
                    $('.videos').append(str);
                    $(".del-photos-btn").click(function () {
                        $(this).parents("tr").eq($(this).index()).remove()
                    });
                    localStorage.removeItem("upload");
                }
            });
        });
        //封面上传
       /* uploadFile({
            elm:'#test5',
            url:"/admin/webupload/postupload",
            table:'.thumbnail',
            multiple:false,
            exts:'jpg|png|bmp|jpeg|avg',
            inputName:'thumbnail'
        });*/
        $("#test5").click(function () {
            uploadFiles({
                url: '/admin/webupload/webuploader/multi/1/filetype/image/app/admin/tab/local',
                file:function (res) {
                    var file = JSON.parse(res);
                    var str = '<tr>'+
                        '<td>'+
                        '<input type="text" class="layui-input" name="thumbnail" value="'+file[0].filepath+'">'+
                        '</td>'+
                        '<td>'+
                        '<img width="80"  src="'+file[0].preview_url+'">'+
                        '</td>'+
                        '<td>'+
                        '<a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs del-photos-btn">删除</a>'+
                        '</td>'+
                        '</tr>';
                    $('.thumbnail').append(str);
                    $(".del-photos-btn").click(function () {
                        $(this).parents("tr").eq($(this).index()).remove()
                    });
                    localStorage.removeItem("upload");
                }
            });
        });
    }
    return Controller;
});